import React from 'react'
import classNames from 'classnames'

import './form-hoc.less'

const prefixCls = 'zhang-form-item'

export default function formItemWrapper(Comp) {

  return class FormItemWrapperComponent extends React.Component {
    static defaultProps = {
      onChange: function () { }
    }

    onChange = (value) => {
      const _key = this.props.fieldname

      this.props.onChange({
        [_key]: value
      })
    }

    render() {
      const { className } = this.props

      const cls = classNames({
        [prefixCls]: true,
        [className]: className
      })
      return (
        <Comp {...this.props} onChange={this.onChange} className={cls} />
      )
    }
  }
}



